package 多线程;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2017/11/10 21:57
 */
public class Demo1 {
    public static void main(String[] args) {
        SellTicket ticket = new SellTicket();
        Thread t1 = new Thread(ticket, "窗口1");
        Thread t2 = new Thread(ticket, "窗口2");
        Thread t3 = new Thread(ticket, "窗口3");
        Thread t4 = new Thread(ticket, "窗口4");
        t1.start();
        t2.start();
        t3.start();
        t4.start();

        //  输出的打印会有重复是因为 CPU在进行高速的切换; 多个线程涌动,因此操作共享资源会出问题

        //线程的相互  唤醒 等待      wait    notify    notifyall

        Message message = new Message("锁");

        Waiter waiter1 = new Waiter(message);
        new Thread(waiter1, "waiter").start();

        Waiter waiter2 = new Waiter(message);
        new Thread(waiter2, "waiter").start();

        Notifier notifier = new Notifier(message);
        new Thread(notifier, "notifier").start();
    }
}
